<template>
	<view class="details">
		<view class="header">
			<view class="user">
				<view>
					<image class="avatar" src="../../static/D-49/image_2_1_3x.png" mode=""></image>
				</view>
				<view class="username">
					<span class="name">甩奶娃</span>
					<span class="describe">我是甩奶娃，是一名吹吹</span>
				</view>
			</view>
			<view class="attention">
				关注
			</view>
		</view>
		<view class="main">
			<view class="text">
				{{dynamicList.words}}
			</view>
			<view class="photo">
				<image :src="dynamicList.picture" mode=""></image>
				<!-- <image v-for="(item,index) in photoList" :key="item.id" src="" mode=""></image> -->
			</view>
			<view class="time">
				{{dynamicList.createTime}}
			</view>
		</view>
		<view class="message">
			<view class="title">
				<span>留言</span>
				<sapn class="number">({{num}})</sapn>
			</view>
			<view class="contain">
				<view class="messageBox">
					<view class="user">
						<view class="avatar">
							<image src="../../static/D-49/image_2_1_3x.png" mode=""></image>
						</view>
						<view class="text">
							<view class="text-title">
								🐢1
							</view>
							<view class="time">
								2019年11月26日 16:21
							</view>
						</view>
						<view class="like" @click= "getLike(dynamicList.id,dynamicList.userId)">
							<image :src="like ? '../../static/icon/like.png' :'../../static/icon/unlike.png'" mode="">
							</image>
							<span>{{likeCount}}</span>
						</view>
					</view>
					<view class="content">
						<view class="text">
							{{dynamicList.words}}
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
		import api from '@/api/api.js'
	export default {
		data() {
			return {
				// 留言数量
				num: 0,
		
				// 点赞数量
				likeCount:null ,
				dynamicList: null,
			}
		},
		methods: {
		
			/**
			 * 获取此话题相关的所有动态
			 */
			async getDynamicList(id) {
				const res = await api.dynamic.getDynamicList(id)
				if (res.code === 200) {
					this.dynamicList = res.data[0]
				}
			},
			// 获取点赞数
			getFindCount(dynamicId) {
					// console.log("bbb")
					// console.log(id)
				api.fabulous.getFindCount(dynamicId).then(res => {
					console.log(res)
					if (res.code === 200) {
						this.likeCount = res.data
					}
				})
			},
			getLike(dynamicId,userId) {
				
			api.fabulous.addFabulou(dynamicId,userId).then(res => {
			console.log(res)
			if (res.code === 200) {
			    this.likeCount++
			}else{
				this.likeCount--
			}	
			})
			
			},
			
		},
		

		onLoad(id) {
			this.getDynamicList(id)
			this.getFindCount(id)
		}
	}
</script>

<style lang="scss" scoped>
	.details {
		width: 100%;
		min-height: 100%;
		padding: 0 30rpx;
		box-sizing: border-box;

		.header {
			width: 100%;
			display: flex;
			padding: 20rpx 0;
			align-items: center;

			.user {
				display: flex;
				flex: 1;

				.avatar {
					width: 60rpx;
					height: 60rpx;
				}

				.username {
					display: flex;
					flex-direction: column;
					height: 60rpx;
					flex: 1;
					padding-left: 15rpx;

					.name {
						font-size: 24rpx;
						color: black;
					}

					.describe {
						color: #C6C6C6;
						font-size: 18rpx;
					}
				}
			}

			.attention {
				padding: 5rpx 25rpx;
				color: #20A564;
				border: 1px solid #20A564;
				border-radius: 20rpx;
				height: 40rpx;
				box-sizing: border-box;
				font-size: 12px;
				display: flex;
				justify-content: center;
				align-items: center;
			}
		}

		.main {
			width: 100%;

			.text {
				font-size: 24rpx;
			}

			.photo {
				width: 48%;
				height: 200rpx;
				margin-top: 15rpx;

				image {
					width: 100%;
					height: 100%;
					border-radius: 5rpx;
				}
			}

			.time {
				margin-top: 30rpx;
				color: #C6C6C6;
				font-size: 20rpx;
			}
		}

		.message {
			margin-top: 40rpx;

			.title {
				font-size: 24rpx;
				margin-bottom: 40rpx;
				display: flex;
				align-items: center;

				.number {
					font-size: 26rpx;
					margin-left: 10rpx;
				}
			}

			.contain {
				.messageBox {
					display: flex;
					flex-direction: column;

					.user {
						display: flex;
						height: 60rpx;
						align-items: center;

						.avatar {
							image {
								width: 60rpx;
								height: 60rpx;
							}
						}

						.text {
							display: flex;
							flex-direction: column;
							margin-left: 10rpx;
							flex: 1;

							.text-title {
								font-size: 24rpx;
								color: black;
							}

							.time {
								color: #C6C6C6;
								font-size: 18rpx;
							}
						}

						.like {
							display: flex;
							align-items: center;
							image {
								width: 32rpx;
								height: 32rpx;
							}

							span {
								font-size: 32rpx;
								color: #C6C6C6;
								margin-left: 5rpx;
							}
						}
					}

					.content {
						margin-top: 30rpx;

						.text {
							font-size: 24rpx;
						}
					}
				}
			}
		}
	}
</style>
